/*
 * @Date: 2022-05-23 10:17:16
 * @LastEditors: sailornpg
 * @LastEditTime: 2022-05-23 10:31:52
 * @FilePath: \my-react-components\src\hooks\useDebounce.ts
 * @Description: something
 */
import React, { useEffect, useState } from "react";
const useDebounce = (value, delay: number = 300) => {
  const [debounceVal, setDebounceVal] = useState(value);
  useEffect(() => {
    const handler = setTimeout(() => {
      setDebounceVal(value);
    }, delay);
    return () => {
      clearTimeout(handler);
    };
  }, [value, delay]);
  return debounceVal;
};
export default useDebounce;
